package com.yyj.util;

import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.Collection;

public class AssertUtil {
    /**
     * 目标值不为null报错
     * @param object
     * @param message
     */
    public static void notNull(@Nullable Object object, String message) {
        if (object != null) {
            throw new RuntimeException(message);
        }
    }

    /**
     * 目标值为null报错
     * @param object
     * @param message
     */
    public static void isNull(@Nullable Object object,String message) {
        if (object == null) {
            throw new RuntimeException(message);
        }
    }

    public static void main(String[] args) {
        System.out.println(org.apache.commons.lang3.StringUtils.isNotBlank(""));
    }
    /**
     *  条件为True报异常
     * @param expression
     * @param message
     */
    public static void isTrue(boolean expression, String message) {
        if (expression) {
            throw new RuntimeException(message);
        }
    }

    /**
     *  条件为False报异常
     * @param message
     */
    public static void isZero( int data, String message) {
        if (data ==0) {
            throw new RuntimeException(message);
        }
    }

    /**
     *  条件为False报异常
     * @param expression
     * @param message
     */
    public static void isFalse(boolean expression, String message) {
        if (!expression) {
            throw new RuntimeException(message);
        }
    }

    /**
     * 集合为空报错
     * @param collection
     * @param message
     */
    public static void notEmpty(@Nullable Collection<?> collection, String message) {
        if (CollectionUtils.isEmpty(collection)) {
            throw new RuntimeException(message);
        }
    }

    /**
     * 字符窜长度为0 或者为null 报异常
     * @param text
     * @param message
     */
    public static void hasLength(@Nullable String text, String message) {
        if (!StringUtils.hasLength(text)) {
            throw new RuntimeException(message);
        }
    }

}
